package br.com.vacinne.dao;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class BDCore extends SQLiteOpenHelper {

	private static final String NOME_BANCO = "BancoVacine";
	private static final int VERSAO_DB =  1;
	
	public BDCore(Context contex) {
		super(contex, NOME_BANCO, null, VERSAO_DB);
	 }

	@Override
	public void onCreate(SQLiteDatabase db) {

		db.execSQL("CREATE TABLE usuario" +
				"(idUsuario Integer PRIMARY KEY AUTOINCREMENT,"+
				"nome Varchar(50) NOT NULL,"+
				"dataNascimento Varchar(10) NOT NULL,"+
				"email Varchar(50) NOT NULL,"+
				"sexo Varchar(15) NOT NULL);"+
				
			"CREATE TABLE vacina("+
				"idVacina Integer PRIMARY KEY AUTOINCREMENT,"+
				"nome Varchar(50) NOT NULL,"+
				"descricao Varchar(500)NOT NULL,"+
				"dataVacina Varchar(10) NOT NULL,"+
				"dataPrazo Varchar(10) NOT NULL);"+
				
			"CREATE TABLE vacinacao"+
				"(idVacinacao Integer PRIMARY KEY AUTOINCREMENT,"+
				"idVacina Integer ,"+
				"idUsuario Integer,"+
				"data Varchar(10) NOT NULL,"+
				"registro Integer NOT NULL);"+
				
	  		"Alter table vacinacao add Foreign Key (idUsuario) references Usuario (idUsuario)"+
				"on delete  restrict on update  restrict;"+
			"Alter table vacinacao add Foreign Key (idVacina) references vacina (idVacina)"+
				"on delete  restrict on update  restrict;"); 
		
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		db.execSQL("drop table usuario; " +
				"drop table vacina;" +
				"drop table vacinacao;");
		onCreate(db);
	}

}
